package org.dean.webapps.projectname.presentation.interceptor;

import org.dean.webapps.projectname.utils.URLUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by IntelliJ IDEA.
 * User: dean
 * Date: 8/22/11
 * Time: 11:28 AM
 * To change this template use File | Settings | File Templates.
 */
public class NoURIRecordingInterceptor extends HandlerInterceptorAdapter {

    private Log log = LogFactory.getLog(this.getClass());

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {

        // Saves Context path of server.
        if (StringUtils.isEmpty(URLUtils.getServerContextPath())) {
            URLUtils.setServerContextPath(request);
        }

        System.out.println("prehandle");

        return super.preHandle(request, response, handler);
    }

    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response,
                           Object handler, ModelAndView modelAndView) throws Exception {
//        modelAndView.getModel().put("context-path", request.getContextPath());
        super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response,
                                Object handler, Exception ex) throws Exception {

        super.afterCompletion(request, response, handler, ex);
    }

}